Home Forums WoodMart support forum Upsells customization add_action problem

Upsells customization add_action problem

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #660873

    Alex
    Participant

    I noticed the peculiarities of the impact of the theme settings in the Single product > Related & Upsells section on the work of add_action

    If you set Hide in the settings of the “Upsells products position” block, then add_action does not work with the function, but it works if you leave it “Standard”

    For example,

    function custom_output_upsells() {
    	global $product;
    	$upsells = $product->get_upsell_ids();
    	if ( empty( $upsells ) ) {
    		return;
    	}
    	
    	echo '<aside class="container related-and-upsells" data-nosnippet="true">';
    	woocommerce_upsell_display( 24, 4 ); 
    	echo '</aside>';
    }
    
    add_action( 'wp', 'remove_miii', 1010 );
    function remove_miii() {
    	if ( ! is_product() ) {
    		return;
    	}
    remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_upsell_display', 15 );
    remove_action( 'woocommerce_after_single_product_summary', 'woodmart_upsells_products', 15 );
    remove_action( 'woocommerce_after_single_product', 'woocommerce_upsell_display', 15 );
    remove_action( 'woocommerce_after_single_product', 'woodmart_upsells_products', 15 );
    remove_action( 'woodmart_woocommerce_after_sidebar', 'woocommerce_upsell_display', 10 );
    remove_action( 'woodmart_woocommerce_after_sidebar', 'woodmart_upsells_products', 10 );
    remove_action( 'woodmart_before_sidebar_area', 'woocommerce_upsell_display', 20 );
    remove_action( 'woodmart_before_sidebar_area', 'woodmart_upsells_products', 20 );
    }
    
    add_action( 'template_redirect', 'dodaty_miii', 101 );
    function dodaty_miii() {
    	if ( ! is_product() ) {
    		return;
    	}
    add_action( 'woocommerce_after_single_product', 'custom_output_upsells', 90 );
    }

    This is one of the examples, I tested different combinations – without remove_action at all, with add_action at the wp level, with remove_action and add_action in one function at the wp level. The result is the same, this setting affects the work of add_action (does not work if Hide)

    PS. At the same time, there is no such problem with Related products. add_action works if in the “Show related products” block of the theme settings – OFF

    #660889

    Hung Pham
    Keymaster

    Hello Alex,

    Thanks for reaching to us.

    1. You should deactivate all plugins (except Required Plugins) and then reactivate them one by one. This makes it very easy to isolate the plugin causing problems.

    2. Could you please check how it works with some default WordPress themes like TwentyTwenty or WooCommerce Storefront to understand is it our theme issue or not?

    Best Regards,

    #660910

    Alex
    Participant

    I didn’t disable the plugins, because they all have to be enabled. Instead, I switched to Twenty Twenty-Five for a minute (because it doesn’t really fit the design and operation of the site) – I see that add_action works

    This confirms that it is the theme settings that affect the operation of add_action

    Here are my plugins, there were no manual changes to the theme code except through these plugins.
    Advanced Google reCAPTCHA, Classic Widgets, Code Snippets (I provided you with a snippet fragment from here, all other snippets do not apply to the product page and cannot affect it), Custom Taxonomy Order, Cyr-To-Lat, GTM4WP – A Google Tag Manager (GTM) plugin for WordPress, Instant Indexing, Loco Translate, MC4WP: Mailchimp for WordPress, Polylang, Polylang for WooCommerce, Print Invoice & Delivery Notes for WooCommerce, PWA, Rank Math SEO, W3 Total Cache, WooCommerce, Woodmart Core, WP-Mail-SMTP

    #660919

    Alex
    Participant

    By the way, after switching between themes, returning to Woodmart Child, I immediately noticed a few things:

    Warning on the main page:
    Warning: Undefined array key “file” in /home/siteua/site.com/www/wp-includes/media.php on line 1768
    Warning: Undefined array key “file” in /home/siteua/site.com/www/wp-includes/media.php on line 1768
    (I change here site name in path)

    Notification in the admin panel:
    Thumbnail regeneration is performed in the background. Depending on the number of images in your store, this will take some time.

    I also noticed that all my customized Woodmart widgets disappeared from the “Store Page Widget Area”. Now they need to be manually restored there.

    This should be warned about when you say to switch the theme for verification.

    #660983

    Alex
    Participant

    I fixed the errors after switching the theme.
    1. Warning: Undefined array key “file” – related to SVG loaded in the blocks of the Gutenberg theme – Infobox.
    It arose due to the loss of the path after switching the theme and the fact that I had long ago disabled the “Allow SVG upload” function and removed the Safe SVG plugin. And I also have Polylang. When switching between themes, thumbnail regeneration was started, which did not occur due to these features.
    I fixed it by enabling the function, the plugin and reloading the SVG.

    3. Regarding widgets – I manually added them again.

    Regarding the Upsells add_action problem, I await your consideration, it looks like an error in the theme.

Tagged: 

Viewing 5 posts - 1 through 5 (of 5 total)