Remove_action () does not work in WordPress plugin

I am new to writing WordPress plugins. I am trying to write a small plugin that changes how the woocommerce plugin displays images on a single product page. In particular, if there is no product image, make a div holding the image "display: none" and not displaying the placeholder image there. The strategy I'm using is to use add_action to render my own version of the woocommerce product_image.php template, and then (try) to use remove_action to prevent the original product_image.php from rendering. The add_action effect clearly works, since I can see the div "display: none" in Firebug. However, remove_action is not executed.

Here is my code:

$add_result = add_action( 'woocommerce_before_single_product_summary', 'eba_wc_show_product_images', 10);

function eba_wc_show_product_images() {
    include( 'eba_product-image.php' );
}

$remove_result = remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 30);
echo "<hr/>result of add_result = " . $add_result . "<hr/>";
echo "<hr/>result of remove_result = " . $remove_result . "<hr/>";

add_action woocommerce_before_single_product_summary hook 20, remove_action 30.

, add_action "1", remove_action . .

+5
2

plugins_loaded, , , .

add_action('plugins_loaded','alter_woo_hooks');

function alter_woo_hooks() {
    $add_result = add_action( 'woocommerce_before_single_product_summary', 'eba_wc_show_product_images', 10);
    $remove_result = remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 10);

    echo "<hr/>result of add_result = " . $add_result . "<hr/>";
    echo "<hr/>result of remove_result = " . $remove_result . "<hr/>";
}

function eba_wc_show_product_images() {
    include( 'eba_product-image.php' );
}
+12

, , - , :

$priority = has_action('action_name', 'function_name');
remove_action('action_name', 'function_name', $priority);

, .

+11

All Articles