Tùy biến do_shortcode('[yith_compare_buttonc]') (ok)

<?php echo do_shortcode('[yith_compare_buttonct product_id="'.$sanPham->ID.'"]') ?>

if(class_exists('YITH_Woocompare_Frontend')) {
  class YITH_Woocompare_Frontend_Ct extends  YITH_Woocompare_Frontend {
  public function compare_button_sct( $atts, $content = null ) {
    $atts = shortcode_atts(array(
        'product' => false,
        'type' => 'default',
        'container' => 'yes',
        'product_id' => 0
    ), $atts);
    $product_id = 0;
    if ( ! $atts['product_id'] ) {
      $product_id = 0;
    }else {
      $product_id = $atts['product_id'];
    }
    if ( empty( $product_id ) ) return '';
    ob_start();
    if ( $atts['container'] == 'yes' ) echo '<div class="woocommerce product compare-button">';
    $this->add_compare_link( $product_id, array(
        'button_or_link' => ( $atts['type'] == 'default' ? false : $atts['type'] ),
        'button_text' => empty( $content ) ? 'default' : $content
    ) );
    if ( $atts['container'] == 'yes' ) echo '</div>';
    return ob_get_clean();
  }
  public function __construct() {
    add_shortcode( 'yith_compare_buttonct', array( $this, 'compare_button_sct' ) );
  }
}
new YITH_Woocompare_Frontend_Ct();
}
<?php echo do_shortcode('[yith_compare_buttonct product_id="'.$sanPham->ID.'"]') ?>

Last updated