douqian1835 2015-12-10 22:55
浏览 68
已采纳

Woocommerce Order Delivery插件更改显示位置

I'm working on a Woocommerce site that is using the following plugin: https://docs.woothemes.com/document/woocommerce-order-delivery/ ("WooCommerce Order Delivery")

The plugin is now displayed on the Checkout page under the billing fields in the checkout_shipping section, I am trying to change this location to the checkout_order_review section by hooking in to the functions.

But I can't seem to get it working.

My code in my functions.php:

function action_woocommerce_checkout_shipping( $instance ) {
global $woocommerce;

  if ( is_checkout() && $woocommerce->cart->needs_shipping() ) {
     echo 'Hi World!';
    if ( wc_od() ){
     echo 'Found wc_od function';
    }

    remove_action( 'woocommerce_checkout_shipping', 'checkout_content' );
  }
};

// add the action
add_action( 'woocommerce_checkout_shipping', 'action_woocommerce_checkout_shipping' );

My thought behind this code was that I remove the function 'checkout_content' which retrieves the plugin template and then add the action to the woocommerce_checkout_order_review function to display it in the order review section.

But my remove_action doesn't seem to work.

The code in the plugin that adds the checkout_content action:

protected function __construct() {
        // WP Hooks.
        add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );

        // WooCommerce hooks.
        add_action( 'woocommerce_checkout_shipping', array( $this, 'checkout_content' ), 99 );
        add_action( 'woocommerce_checkout_process', array( $this, 'validate_delivery_date' ) );
        add_action( 'woocommerce_checkout_update_order_meta', array( $this, 'update_order_meta' ) );

        // Delivery date validation hooks.
        add_filter( 'wc_od_validate_delivery_date', array( $this, 'validate_delivery_day' ), 10, 2 );
        add_filter( 'wc_od_validate_delivery_date', array( $this, 'validate_minimum_days' ), 10, 2 );
        add_filter( 'wc_od_validate_delivery_date', array( $this, 'validate_maximum_days' ), 10, 2 );
        add_filter( 'wc_od_validate_delivery_date', array( $this, 'validate_no_events' ), 10, 2 );
    }

Can someone maybe give me a push in the right direction? Am I doing this wrong ? or is there a better way of achieving this?

  • 写回答

1条回答 默认 最新

  • dsfe167834 2015-12-11 02:01
    关注

    You have two issues.

    Firstly you need to specify the execution priority when you remove action, or at least you do when it is anything other than the default, 10. In your case the execution priority is 99.

    Secondly, checkout_content() is a class function, not a standalone function so you need to specify this in the function reference.

    So your remove_action line of code will be:

    remove_action( 'woocommerce_checkout_shipping', array( $the_class_variable, 'checkout_content' ), 99 );
    

    where $the_class_variable is the instance of the class containing that __construct() function. How you refer to this depends on how the class has been instantiated in the plugin.

    You can read about different ways of instantiating a class and the corresponding remove_action at http://jespervanengelen.com/different-ways-of-instantiating-wordpress-plugins/

    You can read about remove_action this in https://codex.wordpress.org/Function_Reference/remove_action

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀