Just to give you more context. Here’s the code for the test variant:
add_action('woocommerce_single_product_summary', function () {
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 10);
add_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 10);
add_action('woocommerce_single_product_summary', 'woocommerce_gzd_template_single_product_units', 10.1);
add_action('woocommerce_single_product_summary', 'woocommerce_gzd_template_single_price_unit', 10.2);
add_action('woocommerce_single_product_summary', 'woocommerce_gzd_template_single_shipping_costs_info', 10.3);
}, 5);
The only difference to the original is the position that changed from 29 to 10. The remove_action is not really needed here, but I wanted to keep the code as consistent as possible.
Your scope function always has to return something:
if ( is_product() ) {
return true;
}
return false;
But it’s actually way easier this way:
return is_product();
Thanks, David.
It works, but the hook is now duplicated. Do I need some additional condition in the functions.php for the original code?
add_action('woocommerce_single_product_summary', function () {
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 10);
add_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 29);
add_action('woocommerce_single_product_summary', 'woocommerce_gzd_template_single_product_units', 29.1);
add_action('woocommerce_single_product_summary', 'woocommerce_gzd_template_single_price_unit', 29.2);
add_action('woocommerce_single_product_summary', 'woocommerce_gzd_template_single_shipping_costs_info', 29.3);
}, 5);
I could use something like this for the original code:
if ( isset($_GET['nab']) && $_GET['nab'] == '0' ) {...
Not sure whether this is safe to use. The price is crucial information. This has to be super robust. 🙂
Please open a ticket and we’ll look at your site directly.
David helped me with a robust solution that keeps all modifications inside the test configuration. This was a bit tricky in this specific case, since several plugins have some impact on the product page. This is why I had to use some code to place all pricing information right above the add-to-cart button. So, this is not your typical Woocommerce setup.
I use the following code in the B variant:
<?php
add_action('wp_head', function() {
echo '<style>
.woocommerce-product-details__short-description ~ .price,
.woocommerce-product-details__short-description ~ .product-units,
.woocommerce-product-details__short-description ~ .wc-gzd-additional-info {display: none !important;}
.inquiry {margin-bottom: 1.5em;}</style>';
}, 9999);
add_action('woocommerce_single_product_summary', function () {
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 29);
add_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 10);
add_action('woocommerce_single_product_summary', 'woocommerce_gzd_template_single_product_units', 10.1);
add_action('woocommerce_single_product_summary', 'woocommerce_gzd_template_single_price_unit', 10.2);
add_action('woocommerce_single_product_summary', 'woocommerce_gzd_template_single_shipping_costs_info', 10.3);
}, 5);
This removes the duplicate and moves the pricing section to the top. Please note that most hooks used here are specific for the Germanized plugin.
-
This reply was modified 3 weeks, 6 days ago by
cutu234.
-
This reply was modified 3 weeks, 6 days ago by
cutu234.
Thanks for sharing your solution with everyone!