"添加到购物车popup woo commerce" wordpress子主题中的插件代码覆盖

时间:2018-03-26 06:38:38

标签: php wordpress plugins woocommerce cart

这是插件代码。我想覆盖子主题中的函数"get_cart_content()",所以当插件更新没有替换我的代码时。

class Xoo_CP_Core{
         protected static $instance = null;
         //Get instance
         public static function get_instance(){

          if(self::$instance === null){

           self::$instance = new self();

          }
          return self::$instance;
         }
         //Get cart Content

         public function get_cart_content(){

          global $xoo_cp_gl_pden_value;

          global $woocommerce;

          //Get last cart item key

          $cart_item_key = get_option('xoo_cp_added_cart_key');

          if(!$cart_item_key || !$this->action)

           return;
          //Remove from the database

          delete_option('xoo_cp_added_cart_key');

          $cart = WC()->cart->get_cart();

          $cart_item = $cart[$cart_item_key];

          $_product   = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );

          $attributes1  = json_decode($_product);

          /*$ddd = (array)$attributes1->attributes;
          $ddd = $ddd['pa_download-options'];*/

          $checkvirtual = $attributes1->virtual;

          $checkDownloadable = $attributes1->downloadable;

          $variation_id_new = $attributes1->id;
          $product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key );
          $notice = $this->get_notice_html($product_id,$cart_item_key,$variation_id_new);
          if ($checkvirtual == 1 || $checkDownloadable == 1) {
           $_SESSION['custCheck-'.$variation_id_new] = $variation_id_new;
           $woocommerce->cart->set_quantity($cart_item_key, '1');
          }
          if($this->action == 'remove' || !$xoo_cp_gl_pden_value){
           return $notice;
          }
          $args = array(
                   'cart_item_key' => $cart_item_key,
                   'action'   => $this->action
                  );
          ob_start();
          wc_get_template('xoo-cp-content.php',$args,'',XOO_CP_PATH.'/templates/');
          return $notice.ob_get_clean();
        }

如果有人这样做之前请建议我,所以我可以这样做,我是WordPress的新手。我之前没有完成这种类型的挑战。

提前致谢

0 个答案:

没有答案