Complete the code to activate WooCommerce plugin in WordPress.
<?php
/* Plugin Name: Sample Store */
function activate_woocommerce() {
if ( ! class_exists( '[1]' ) ) {
// WooCommerce is not active
}
}
add_action( 'plugins_loaded', 'activate_woocommerce' );The WooCommerce plugin defines the WooCommerce class. Checking if this class exists confirms if WooCommerce is active.
Complete the code to add a WooCommerce product to the cart.
function add_product_to_cart() {
$product_id = 123;
WC()->cart->[1]( $product_id );
}The correct WooCommerce function to add a product to the cart is add_to_cart.
Fix the error in the WooCommerce shortcode to display products.
echo do_shortcode( '[products [1]="4"]' );
The correct attribute to specify the number of products in the WooCommerce shortcode is number.
Fill both blanks to create a WooCommerce product query for featured products.
$args = [
'post_type' => 'product',
'meta_key' => '[1]',
'meta_value' => '[2]'
];WooCommerce uses the meta key _featured with value yes to mark featured products.
Fill all three blanks to register a custom WooCommerce product tab.
add_filter( 'woocommerce_product_tabs', function( $tabs ) { $tabs['[1]'] = [ 'title' => '[2]', 'callback' => '[3]' ]; return $tabs; });
The tab key is 'custom_tab', the title is 'Additional Info', and the callback function is 'custom_tab_content'.